/*==============================================================================
 * AUTH: Matthew Baum, 9753095
 * DATE: January-27-2012
 * DESC: "Static" Java class containing data processing methods.
 *==============================================================================*/

package Phase_1;

import java.util.ArrayList;
import java.util.HashMap;

public final class DataHelpers {

    // Cannot be instanciated
    private DataHelpers()
    {
        // Do nothing
    }

    // Generate list of employee names
    public static ArrayList<String> listEmployees(Task[] tasks)
    {
        // Create list to hold distinct employee names
        ArrayList<String> listOfNames = new ArrayList<String>();

        // Add first name (must be distinct)
        listOfNames.add( tasks[0].getAssignee() );

        // Loop through tasks and add distinct names
        for(int i = 0; i != tasks.length; ++i)
        {
            // IF unique
            if(! listOfNames.contains( tasks[i].getAssignee() ) )
            {
                // Add the name
                listOfNames.add( tasks[i].getAssignee() );
            }
        }

        // Return a reference to the list of names obtained:
        return listOfNames;
    }

    // Given array of Tasks, return HashMap of employeeName/taskList
    public static HashMap<String, ArrayList<Task> > getTaskAssignments(Task[] tasks)
    {
        // Hash Map to keep track of task assignments
        HashMap<String, ArrayList<Task> > taskAssignments = new HashMap<String, ArrayList<Task> >();

        // Iterate through the Task array
        for(int i = 0; i != tasks.length; ++i)
        {
            // IF employee name does not exist in the Map, add it
            if(! taskAssignments.containsKey(tasks[i].getAssignee() ) )
            {
                taskAssignments.put(tasks[i].getAssignee(), new ArrayList<Task>());
            }

            // Associate employee and Task in the Map
            taskAssignments.get(tasks[i].getAssignee() ).add( tasks[i] );
        }

        // Return a reference to the complete Map
        return taskAssignments;
    }
}
